package top.kaoshanji.p2ch15a;

/**
 * 代码清单-p2ch15a-442页a：synchronized代码块修饰的Counter类
 * author kaoshanji
 * ^_^
 * create time 2025/2/23 18:09
 */
public class Counter2 {

    // 这是个实例属性
    private int count;

    public void incr() {
        // 实例属性使用 this
        synchronized (this) {
            count++;
        }
    }

    public int getCount() {
        synchronized (this) {
            return count;
        }
    }

}
